package model.net
{
	import core.Model;
	
	import flash.utils.ByteArray;
	
	import global.GameState;
	import global.GameType;
	
	import model.NetDataParserModel;
	import model.system.TraceManager;

	public class AbsDataHandler
	{
		protected var  _model:Model = Model.getInstance();
		
		public function AbsDataHandler()
		{
			
		}
		
		protected function register(id:int,parserFunction:Function):void
		{
			NetDataParserModel.getInstance().register(id,parserFunction);
		}
		
		protected function readString(byteArray:ByteArray):String
		{
			var length:int;
			if (GameState.DEBUG_STATE == GameType.GAME_DEBUG_OFF)
			{
				try
				{
					length = byteArray.readShort();
					return byteArray.readMultiByte(length,NetDataType.DEFAULT_CHARSET);
				}
				catch (e:Error)
				{
					TraceManager.getInstance().out(e.getStackTrace());
					return null;
				}
			}
			else
			{
				length = byteArray.readShort();
				return byteArray.readMultiByte(length,NetDataType.DEFAULT_CHARSET);
			}
			
			return null;
			
		}
		
	}
}